<?php namespace web\admin\controller;
/*
* 友情链接控制器
*/


class Link extends Common{
    protected $db;
    public function __construct(){
        parent::__construct();
        $this->db = new \system\model\Link();
    }
    //首页
    public function index(){
        $data = $this->db->get();
        View::with('data',$data)->make();
    }
    //添加
    public function add(){
        if(IS_POST){
            if($this->db->store()){
                message('添加成功',u('index'),'success');
            }
              message($this->db->getError(),'back','error');
        }
        View::make();
    }
    //编辑
    public function edit(){
        if(IS_POST){
            if($this->db->edit()){
                message('编辑成功',u('index'),'success');
            }
              message($this->db->getError(),'','error');
        }
        //获取旧数据
        $lid = q('get.lid',0,intval);
        $newdata = $this->db->where('lid',$lid)->first();
        View::with('newdata',$newdata)->make();
    }
    //删除
    public function del(){
       $lid = q('get.lid',0,'intval');
        $this->db->where('lid',$lid)->delete();
        message('删除成功',u('index'),'success');
    }

}
